using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace BizTalkCrossReferenceManager.UI.Generation
{
    public partial class BizTalkCrossReferenceFilesGenerationForm : Form
    {
        public BizTalkCrossReferenceFilesGenerationForm()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {            
            string folderPath = OutputFolderPathTextBox.Text;
            string btsXrefImportExePath = BtsXRefImportPathTextBox.Text;

            if (string.IsNullOrEmpty(folderPath) || !Directory.Exists(folderPath))
            {
                MessageBox.Show("Please select a valid output folder");
                return;
            }
            if (string.IsNullOrEmpty(btsXrefImportExePath) || !File.Exists(btsXrefImportExePath))
            {
                MessageBox.Show("Please select a valid path for the Bts XRef Import Tool");
                return;
            }

            Generators.BtsSetupFilesGenerator.Generate(folderPath);
            Generators.BtsAppTypeGenerator.Generate(folderPath);
            Generators.BtsAppInstanceGenerator.Generate(folderPath);
            Generators.BtsIdXRefDataGenerator.Generate(folderPath);
            Generators.BtsIdXRefGenerator.Generate(folderPath);
            Generators.BtsMessageDefinitionGenerator.Generate(folderPath);
            Generators.BtsMessageTextGenerator.Generate(folderPath);
            Generators.BtsValueXRefDataGenerator.Generate(folderPath);
            Generators.BtsValueXRefGenerator.Generate(folderPath);
            Generators.BTSCommandFileGenerator.Generate(folderPath, btsXrefImportExePath);

            MessageBox.Show("The BizTalk Cross Reference Files are now generated");
        }

        private void button2_Click(object sender, EventArgs e)
        {
            DialogResult dr = openFileDialog1.ShowDialog();
            if (dr == DialogResult.OK)
                BtsXRefImportPathTextBox.Text = openFileDialog1.FileName;
        }

        private void button3_Click(object sender, EventArgs e)
        {
            DialogResult dr = folderBrowserDialog1.ShowDialog();
            if (dr == DialogResult.OK)
                OutputFolderPathTextBox.Text = folderBrowserDialog1.SelectedPath;
        }
    }
}